package cn.websocket.web.controller;

import cn.websocket.config.WebSocketServer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
public class HelloController {
    @RequestMapping("/sendMsg")
    public String sendMsg(String token,String msg) throws IOException {
        WebSocketServer webSocketServer = WebSocketServer.clients.get(token);
        if(webSocketServer!=null){
            webSocketServer.getSession().getBasicRemote().sendText(msg);
        }
        return "发送成功";
    }
}
